package com.example.config;

import com.example.myweird2.OtherBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 一个最简单的 自动装配的配置类
 */
@Configuration
//@ConditionalOnClass(name = "com.example.myweird2.OtherBean") //这两种效果一样
@ConditionalOnClass(OtherBean.class)//这两种效果一样
public class MyOtherBeanAutoConfiguration {

    @Bean("bean2")
    @ConditionalOnMissingBean(OtherBean.class)
    public OtherBean getOtherBean() {
        return new OtherBean("other things");
    }
}
